﻿#include "stdafx.h"
#include "XShapeIntParser.h"

#include "XBSTR.h"
#include "XString.h"
#include "Util.h"
#include "IXShape.h"

#include "ParseHelper.h"


CXShapeIntParser::CXShapeIntParser() : CXIntParserBase(&TIntCreateControl<IXShape>)
{
    ;
}

CXShapeIntParser::~CXShapeIntParser()
{
    ;
}

// 填充属性
BOOL CXShapeIntParser::FillAttr(IN IXConfigNode* pNode, IN IXControl* pControl)
{
    BOOL bResult = m_ParentParser.FillAttr(pNode, pControl);
    if(!bResult)
        return bResult;

    XBSTR bstrTemp;
    BOOL bTemp;
    int nTemp;
    COLORREF clrTemp;

    IXShape* pShape = Util::QueryIntf<IXShape>(pControl);
    if(pShape == NULL)
        return FALSE;

    // Shape
    if(SUCCEEDED(pNode->GetValue(_T("shape"), &bstrTemp)))
    {
        ShapeType type = Shape_Rect;
        if(bstrTemp == _T("roundRect"))
            type = Shape_RoundRect;
        else if(bstrTemp == _T("rect"))
            type = Shape_Rect;
        else if(bstrTemp == _T("line"))
            type = Shape_Line;
        else
            type = Shape_None;
        if(Shape_None != type)
            pShape->put_ShapeType(type);
    }

    // BorderWidth
    if(SUCCEEDED(pNode->GetValue(_T("borderWidth"), &nTemp)))
    {
        pShape->put_BorderWidth(nTemp);
    }

    // BorderColor
    if(SUCCEEDED(pNode->GetValue(_T("borderColor"), &clrTemp)))
    {
        pShape->put_BorderColor(clrTemp);
    }

    // BorderCorner
    if(SUCCEEDED(pNode->GetValue(_T("borderCorner"), &nTemp)))
    {
        pShape->put_BorderCorner(nTemp);
    }

    // ContentColor
    if(SUCCEEDED(pNode->GetValue(_T("contentColor"), &clrTemp)))
    {
        pShape->put_ContentColor(clrTemp);
    }

    // contTrans
    if(SUCCEEDED(pNode->GetValue(_T("contTrans"), &bTemp)))
    {
        pShape->put_ContentTransparent(bTemp);
    }

    return bResult;
}
